/**
 * @brief 验证以下场景下close fd对本地write的影响：
 * 先连续write，直到阻塞，再close fd
 */

#include<sys/types.h>
#include<sys/socket.h>
#include<stdio.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<unistd.h>
#include<pthread.h>
#include<stdlib.h>

int main(void)
{
    int server_sockfd, client_sockfd;
    int server_len, client_len;
    struct sockaddr_in server_address;
    struct sockaddr_in client_address;
    pthread_t tid;

    server_sockfd = socket(AF_INET, SOCK_STREAM, 0);

    server_address.sin_family = AF_INET;
    //注意：inet_addr返回的已经是按照网络字节序存储的网络地址了，所以不能再加htonl了    
    server_address.sin_addr.s_addr = inet_addr("192.168.33.92");
    server_address.sin_port = htons(11021);
    server_len = sizeof(server_address);
    bind(server_sockfd, (struct sockaddr*)&server_address, server_len);

    listen(server_sockfd, 5);
    printf("server waiting\n");

    client_len = sizeof(client_address);
    client_sockfd = accept(server_sockfd, (struct sockaddr*)&client_address, &client_len);

    printf("client connected.\n");


    while (1)
    {
        sleep(5);
    }

    printf("server end!!!!\n");

    return 0;
}
